import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Lily
 * Date: 2024-10-16
 * Time: 20:02
 */
public class test_2 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextInt()) { // 注意 while 处理多个 case
            int len = in.nextInt();
            int[] nums = new int[len];
            int min = -1;
            int x = 10001;
            for (int i = 0; i < len; i++) {
                nums[i] = in.nextInt();
                x = Math.min(x, nums[i]);
                min = Math.max(min, nums[i] - x);
            }

            System.out.println(Math.max(min, 0));
        }
    }
}
